package cc.uncarbon.module.appapi.web.app;

import cc.uncarbon.framework.web.model.response.ApiResult;
import cc.uncarbon.module.appapi.constant.AppApiConstant;

import cc.uncarbon.module.appapi.model.response.BannerBO;
import cc.uncarbon.module.appapi.model.response.BlinkBO;
import cc.uncarbon.module.appapi.model.response.ItemBO;
import cc.uncarbon.module.appapi.model.vo.IndexVO;
import cc.uncarbon.module.appapi.service.BannerService;
import cc.uncarbon.module.appapi.service.BlinkService;
import cc.uncarbon.module.appapi.service.ItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "小程序首页")
@RequestMapping(AppApiConstant.HTTP_API_URL_PREFIX + "/api/v1")
@RequiredArgsConstructor
@RestController
@Slf4j
public class IndexController {
    private final BannerService bannerService;

    private final ItemService itemService;

    private final BlinkService blinkService;

    @Operation(summary = "首页")
    @GetMapping("/index/{storeId}")
    public ApiResult<IndexVO> index(@PathVariable("storeId") Long storeId) {

        // 轮播图
        List<BannerBO> list = bannerService.getList(storeId);
        // 项目
        List<ItemBO> item = itemService.getList(storeId);
        //金刚区图标
        List<BlinkBO> blink = blinkService.getList(storeId);
        IndexVO vo = new IndexVO();
        vo.setBanner(list);
        vo.setItem(item);
        vo.setBlink(blink);
        return ApiResult.data(vo);
    }
}
